# Contributor: Will Sinatra <wpsinatra@gmail.com>
# Maintainer: Will Sinatra <wpsinatra@gmail.com>
maintainer="Will Sinatra <wpsinatra@gmail.com>"
pkgname=amazon-ssm-agent
pkgver=3.3.1230.0
pkgrel=0
pkgdesc="Amazon SSM Agent for managing EC2 Instances using the SSM APIs."
url="https://aws.amazon.com/documentation/systems-manager/"
license="Apache-2.0"
arch="all !s390x !riscv64 !ppc64le !loongarch64"
# armv7/armhf/x86 complains about cgo linking not being enabled
makedepends="go gcompat bash"
source="https://github.com/aws/amazon-ssm-agent/archive/$pkgver/amazon-ssm-agent-$pkgver.tar.gz
	amazon-ssm-agent.initd
	001_sanitize_makefile.patch"
subpackages="$pkgname-openrc"
options="!check net"
_binaries="amazon-ssm-agent
	ssm-agent-worker
	ssm-cli
	ssm-document-worker
	ssm-session-logger
	ssm-session-worker
	ssm-setup-cli
	"

case "$CARCH" in
	armhf) _build_arch=arm ;;
	armv7) _build_arch=arm ;;
	x86) _build_arch=386 ;;
	x86_64) _build_arch=amd64 ;;
	aarch64) _build_arch=arm64 ;;
esac

build() {
	make build-linux-$_build_arch
}

package() {
	for bin in $_binaries; do
		install -Dm0755 "$builddir"/bin/linux_$_build_arch/$bin "$pkgdir"/usr/bin/$bin
	done

	install -Dm0644 "$builddir"/bin/amazon-ssm-agent.json.template \
		"$pkgdir"/etc/amazon/ssm/amazon-ssm-agent.json.template
	install -Dm0644 "$builddir"/bin/seelog_unix.xml \
		"$pkgdir"/etc/amazon/ssm/seelog.xml
	install -Dm0644 "$builddir"/bin/seelog_windows.xml.template \
		"$pkgdir"/etc/amazon/ssm/seelog_windows.xml.template

	install -Dm0755 "$srcdir"/amazon-ssm-agent.initd \
		"$pkgdir"/etc/init.d/amazon-ssm-agent
}

sha512sums="
8d665f1f359a60d9e18645380787c5c9c1608f0eff22152dc04514afba12036171bfa84ef8c55965dd83e7cc4c3d95805d7f0072f46062b3a51f4721ef1032a8  amazon-ssm-agent-3.3.1230.0.tar.gz
af6689774101d258968709b9782c9d9e1965c3b96ffe61175db61264aaf8604fb4e27c65a97bb99d39869189c82fe5e04b2bc87dcd61cfe6ba1f3739fce7aefe  amazon-ssm-agent.initd
d90a10ed7f3cf0a58bb73f737c2d10d56b3942886535df7d9215e2cf809c59ef708ed4d9775062e46343cf64726d25adaf048c86f39d4a7647deebd91d69c2f9  001_sanitize_makefile.patch
"
